 //初始化
 let rooms = getData('room')  //取所有房间信息
 let checkInOrders = getData('checkInOrder') //取所有订单信息
 let clients = getData('client') //取所有房客信息
 let nowNav = $('section .navbar-nav>li').eq(0) //储存当前所在二级导航页
 let nowloginUser = getData('loginUser') //取登录者信息
 //let nowloginUser = { id: 14, jobNumber: 10014, password: '12345', userName: '李四', sex: '女', Birthdate: '1990/12/12', tel: '133xxxxx', headPortrait: '../images/后勤.webp', AccessLevel: 1, jobTitle: '后勤' }
 let nowAccessLevel = nowloginUser.AccessLevel //取登录者权限等级
 //根据角自动选择次级菜单
 //如果是后勤自动打开待清洁 否则自动打开入住
 if (nowAccessLevel == 2) {
     $('section .navbar-nav>li').eq(2).addClass('active').siblings().removeClass('active')
     awaitSweep()
 } else {
     checkIn()
 }

 //清除表单按钮默认事件
 $('button').on('click', function () {
     //清除表单中按钮的默认提交事件
     event.preventDefault()
 })

 //点击主菜单样式改变
 $('#mianNav .navbar-nav>li').on('click', function () {
     //设置自身为选中状态并清除其他选项的选中状态
     $(this).addClass('mianActive').siblings().removeClass('mianActive')
 })

 //点击二级菜单
 $('section .navbar-nav>li').on('click', function () {
     //更新数据
     rooms = getData('room')  //取所有房间信息
     checkInOrders = getData('checkInOrder') //取所有订单信息
     clients = getData('client') //取所有房客信息
     //储存当前二级导航页
     nowNav = $(this)
     //设置自身为选中状态并清除其他选项的选中状态
     $(this).addClass('active').siblings().removeClass('active')
     //显示对应功能区
     switch ($(this).text()) {
         case '入住': nowAccessLevel <= 1 ?checkIn():insufficientPrivileges(); break;
         case '退房': nowAccessLevel <= 1 ?checkOut():insufficientPrivileges(); break;
         case '待清洁房间': awaitSweep(); break;
         case '全部房间': nowAccessLevel <= 1 ?allRooms():insufficientPrivileges(); break;
         case '客房编辑': nowAccessLevel == 0 ? editRooms() : insufficientPrivileges(); break;
     }
 })

 //入住数据加载
 function checkIn() {
     //隐藏分页按钮
     $('#editRoomsbutts').removeClass('editRoomsbutts')
     //显示入住功能页
     $('main>.optionBody').eq(0).show().siblings().hide()

     //加载待入住大房间信息
     //清空原来的大房间数据
     $('#checkIn .bigRooms').html('')
     let nowBigRooms = []  //大房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待入住大房间数据
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '待入住') {
             $('#checkIn .bigRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }
     }
     if ($('#checkIn .bigRooms').html() == '') {
         $('#checkIn .bigRooms').append(`
                 <p>暂无空闲大房间</p>
             `)
     }

     //加载待入住中房间信息
     //清空原来的中房间数据
     $('#checkIn .middleRooms').html('')
     let nowMiddleRooms = []  //中房间号数组
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '待入住') {
             $('#checkIn .middleRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#checkIn .middleRooms').html() == '') {
         $('#checkIn .middleRooms').append(`
                 <p>暂无空闲中房间</p>
             `)
     }

     //加载待入住小房间信息
     //清空原来的小房间数据
     $('#checkIn .littleRooms').html('')
     let nowlittleRooms = []  //小房间号数组
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '待入住') {
             $('#checkIn .littleRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#checkIn .littleRooms').html() == '') {
         $('#checkIn .littleRooms').append(`
                 <p>暂无空闲小房间</p>
             `)
     }
 }

 //办理入住
 //点击对应房间弹出入住信息填写
 $('#checkIn').on('click', 'li', function () {
     //清除原来的输入内容
     let inputName = $('#name').val('')
     let inputTel = $('#tel').val('')
     let inputIdNum = $('#idNum').val('')
     let inputSex = $('#sex').val('')
     let inputCashPledge = $('#cashPledge').val('')
     let inputRemarks = $('#remarks').val('')
     //获取所点击房间号
     let nowRoomNum = $(this).text()
     let nowRoom //储存所点击房间全部信息
     //显示入住信息填写框
     $('#checkInOperation').modal('show')
     //遍历房间数组
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].roomNumber == nowRoomNum) {
             //储存所点击房间信息
             nowRoom = rooms[i]
             break;
         }
     }
     $('#roomInformation>li').eq(0).text(`\xa0\xa0房间号:${nowRoomNum}`)
     $('#roomInformation>li').eq(1).text(`\xa0\xa0\xa0规格:${nowRoom.RoomSize}`)
     $('#roomInformation>li').eq(2).text(`\xa0\xa0\xa0价格:${nowRoom.price}`)
 })
 //点击确认入住后生成订单以及房客信息和改变房间状态
 $('#confirm').on('click', function () {
     //取输入框值
     let inputName = $('#name').val()
     let inputTel = $('#tel').val()
     let inputIdNum = $('#idNum').val()
     let inputSex = $('#sex').val()
     let inputCashPledge = $('#cashPledge').val()
     let inputRemarks = $('#remarks').val()

     //取房间号规格价格
     let nowRoomNum = $('#roomInformation>li').eq(0).text().slice(6)
     let nowRoomRoomSize = $('#roomInformation>li').eq(1).text().slice(6)
     let nowRoomPrice = $('#roomInformation>li').eq(2).text().slice(6)

     //遍历房间
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].roomNumber == nowRoomNum) {
             //改房间状态
             rooms[i].roomState = '已入住'
             //更新房间数据库数据
             saveData('room', rooms)
             //生成订单
             let nowNewId = checkInOrders[checkInOrders.length - 1].id  //当前最新订单id
             let nowNewOrderNumber = Number(checkInOrders[checkInOrders.length - 1].orderNumber)   //当前最新订单号
             let newId = 'd' + (Number(nowNewId.slice(1)) + 1) //生成订单id
             //判断今日是否生成过订单
             let whether = false //是否生成过今日的第一个订单状态
             for (let j = 0; j < checkInOrders.length; j++) {
                 if (checkInOrders[j].orderNumber == getTime2() + '001') {
                     whether = true;
                     break;
                 }
             }
             let neworderNumber = whether ? nowNewOrderNumber + 1 + '' : getTime2() + '001'
             let newCheckInOrderObj = {
                 id: newId, orderNumber: neworderNumber, roomNumber: nowRoomNum, checkInTime: getTime(), price: nowRoomPrice,
                 cashPledge: inputCashPledge, clientName: inputName, orderState: '入住中', remarks: inputRemarks, inputter: nowloginUser.userName
             }
             //新增订单
             checkInOrders.push(newCheckInOrderObj)
             //存到数据库
             saveData('checkInOrder', checkInOrders)

             //生成房客数据
             // id(id)	客人名字(clientName) 性别(sex)	手机号(tel)	身份证(idNo) 房间号(roomNumber)	备注(remarks)
             let nowNewCId = clients[clients.length - 1].id  //当前最新房客id
             let newCId = 'c' + (Number(nowNewId.slice(1)) + 1)
             let newClientObj = {
                 id: newCId, clientName: inputName, sex: inputSex, tel: inputTel,
                 idNo: inputIdNum, roomNumber: nowRoomNum, remarks: inputRemarks
             }
             //新增房客信息
             clients.push(newClientObj)
             //保存到数据库
             saveData('client', clients)

             //刷新当前页面数据
             nowNav.click()
             break
         }
     }
 })

 //退房数据加载
 function checkOut() {
     //隐藏分页按钮
     $('#editRoomsbutts').removeClass('editRoomsbutts')
     //显示退房功能页
     $('main>.optionBody').eq(1).show().siblings().hide()

     //加载待入住大房间信息
     //清空原来的大房间数据
     $('#checkOut .bigRooms').html('')
     let nowBigRooms = []  //大房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待入住大房间数据
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '已入住') {
             $('#checkOut .bigRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#checkOut .bigRooms').html() == '') {
         $('#checkOut .bigRooms').append(`
                 <p>暂无可退房大房间</p>
             `)
     }

     //加载待入住中房间信息
     //清空原来的中房间数据
     $('#checkOut .middleRooms').html('')
     let nowMiddleRooms = []  //中房间号数组
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '已入住') {
             $('#checkOut .middleRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#checkOut .middleRooms').html() == '') {
         $('#checkOut .middleRooms').append(`
                 <p>暂无可退房中房间</p>
             `)
     }

     //加载待入住小房间信息
     //清空原来的小房间数据
     $('#checkOut .littleRooms').html('')
     let nowlittleRooms = []  //小房间号数组
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '已入住') {
             $('#checkOut .littleRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#checkOut .littleRooms').html() == '') {
         $('#checkOut .littleRooms').append(`
                 <p>暂无可退房小房间</p>
             `)
     }
 }

 //办理退房鼠标点击显示操作
 $('#checkOut').on('mouseenter', 'li', function () {
     $('#checkOut li').find('.affirmCheckOutBox').remove()
     if (!($(this).children('.affirmCheckOutBox').length))
         $(this).append(`
     <div class="affirmCheckOutBox">
         <div class="affirmCheckOut">退房</div>
         <div class="cancelCheckIn">取消入住</div>
     </div>
    `)
 })
 //办理退房鼠标移出删除显示操作
 $('#checkOut').on('mouseleave', 'li', function () {
     $('#checkOut li').find('.affirmCheckOutBox').remove()
 })
 //点击退房
 $('#checkOut').on('click', '.affirmCheckOut', function () {
     //弹出确认退房提示框
     $('#checkOutOperation').modal('show')
     let nowRoomNum = parseInt($(this).parents('li').text()) //当前选择房间号
     $('#checkOutOperation .modal-body').text(`${nowRoomNum}号房确定要执行退房操作吗？`)
 })
 //确认退房
 $('#confirmcheckOut').on('click', function () {
     //取房间号
     let nowRoomNum = parseInt($('#checkOutOperation .modal-body').text())

     //更改房间状况
     for (let i = 0; i < rooms.length; i++) {
         if (nowRoomNum == rooms[i].roomNumber) {
             console.log('退房成功');
             rooms[i].roomState = '待清洁'
             break;
         }
     }
     //更改订单状态
     for (let i = 0; i < checkInOrders.length; i++) {
         if (checkInOrders[i].orderState == '入住中' && checkInOrders[i].roomNumber == nowRoomNum) {
             checkInOrders[i].orderState = '已完成'
         }
     }
     //更新数据库
     saveData('room', rooms)
     saveData('checkInOrder', checkInOrders)
     //刷新当前页面数据
     nowNav.click()
 })

 //点击取消入住
 $('#checkOut').on('click', '.cancelCheckIn', function () {
     //弹出确认退房提示框
     $('#cancelCheckInOperation').modal('show')
     let nowRoomNum = parseInt($(this).parents('li').text()) //当前选择房间号
     $('#cancelCheckInOperation .modal-body').text(`${nowRoomNum}号房确定要执行取消入住操作吗？`)
 })
 //确认取消入住
 $('#confirmcancelCheckIn').on('click', function () {
     //取房间号
     let nowRoomNum = parseInt($('#cancelCheckInOperation .modal-body').text())

     //更改房间状况
     for (let i = 0; i < rooms.length; i++) {
         if (nowRoomNum == rooms[i].roomNumber) {
             rooms[i].roomState = '待入住'
             break;
         }
     }
     //更改订单状态
     for (let i = 0; i < checkInOrders.length; i++) {
         if (checkInOrders[i].orderState == '入住中' && checkInOrders[i].roomNumber == nowRoomNum) {
             checkInOrders[i].orderState = '已取消'
         }
     }
     //更新数据库
     saveData('room', rooms)
     saveData('checkInOrder', checkInOrders)
     //刷新当前页面数据
     nowNav.click()
 })

 //待清洁房间数据加载
 function awaitSweep() {
     //隐藏分页按钮
     $('#editRoomsbutts').removeClass('editRoomsbutts')
     //显示待清洁功能页
     $('main>.optionBody').eq(2).show().siblings().hide()
     //加载待清洁大房间信息
     //清空原来的大房间数据
     $('#awaitSweep .bigRooms').html('')
     let nowBigRooms = []  //大房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待清洁大房间数据
         //展示待清洁大房间
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '待清洁') {
             $('#awaitSweep .bigRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#awaitSweep .bigRooms').html() == '') {
         $('#awaitSweep .bigRooms').append(`
                 <p>暂无待清洁大房间</p>
             `)
     }

     //载入待清洁中房间数据
     //展示待清洁中房间
     $('#awaitSweep .middleRooms').html('')
     let nowmiddleRooms = []  //中房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待清洁中房间数据
         //展示待清洁中房间
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '待清洁') {
             $('#awaitSweep .middleRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#awaitSweep .middleRooms').html() == '') {
         $('#awaitSweep .middleRooms').append(`
                 <p>暂无待清洁中房间</p>
             `)
     }

     //载入待清洁小房间数据
     //展示待清洁小房间
     $('#awaitSweep .littleRooms').html('')
     let nowlittleRooms = []  //小房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待清洁小房间数据
         //展示待清洁小房间
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '待清洁') {
             $('#awaitSweep .littleRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#awaitSweep .littleRooms').html() == '') {
         $('#awaitSweep .littleRooms').append(`
                 <p>暂无待清洁小房间</p>
             `)
     }
 }
 //清洁房间鼠移入显示操作
 $('#awaitSweep').on('mouseenter', 'li', function () {
     $('#awaitSweep li').find('.affirmCheckOutBox').remove()
     if (!($(this).children('.affirmCheckOutBox').length))
         $(this).append(`
     <div class="affirmCheckOutBox">
         <div class="affirmAwaitSweep">已清洁</div>
     </div>
    `)
 })
 //鼠标移出删除操作按钮
 $('#awaitSweep').on('mouseleave', 'li', function () {
     $('#awaitSweep li').find('.affirmCheckOutBox').remove()
 })
 //点击已清洁
 $('#awaitSweep').on('click', '.affirmAwaitSweep', function () {
     //弹出确认退房提示框
     $('#awaitSweepOperation').modal('show')
     let nowRoomNum = parseInt($(this).parents('li').text()) //当前选择房间号
     $('#awaitSweepOperation .modal-body').text(`${nowRoomNum}号房确定执行已清洁操作吗？`)
 })
 //确认已清洁
 $('#confirmawaitSweep').on('click', function () {
     //取房间号
     let nowRoomNum = parseInt($('#awaitSweepOperation .modal-body').text())

     //更改房间状况
     for (let i = 0; i < rooms.length; i++) {
         if (nowRoomNum == rooms[i].roomNumber) {
             rooms[i].roomState = '待入住'
             console.log('清洁完成');
             break;
         }
     }
     //更新数据库
     saveData('room', rooms)
     //刷新当前页面数据
     nowNav.click()
 })

 //全部房间数据加载
 function allRooms() {
     //隐藏分页按钮
     $('#editRoomsbutts').removeClass('editRoomsbutts')
     //显示全部房间功能页
     $('main>.optionBody').eq(3).show().siblings().hide()

     //加载待入住大房间信息
     //清空原来的大房间数据
     $('#allRooms .bigRooms').html('')
     let nowBigRooms = []  //大房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //载入待入住大房间数据
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '待入住') {
             $('#allRooms .bigRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示已入住大房间
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '已入住') {
             $('#allRooms .bigRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示待清洁房间
         if (rooms[i].RoomSize == '大' && rooms[i].roomState == '待清洁') {
             $('#allRooms .bigRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }
     }
     if ($('#allRooms .bigRooms').html() == '') {
         $('#allRooms .bigRooms').append(`
                     <p>暂无大房间</p>
                 `)
     }


     //加载待入住中房间信息
     //清空原来的中房间数据
     $('#allRooms .middleRooms').html('')
     let nowMiddleRooms = []  //中房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //展示待入住房间
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '待入住') {
             $('#allRooms .middleRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示已入住房间
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '已入住') {
             $('#allRooms .middleRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示待清洁房间
         if (rooms[i].RoomSize == '中' && rooms[i].roomState == '待清洁') {
             $('#allRooms .middleRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#allRooms .middleRooms').html() == '') {
         $('#allRooms .middleRooms').append(`
                 <p>暂无中房间</p>
             `)
     }

     //加载待入住小房间信息
     //清空原来的小房间数据
     $('#allRooms .littleRooms').html('')
     let nowlittleRooms = []  //小房间号数组
     for (let i = 0; i < rooms.length; i++) {
         //展示待入住房间
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '待入住') {
             $('#allRooms .littleRooms').append(`
                 <li class='checkIn'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示已入住房间
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '已入住') {
             $('#allRooms .littleRooms').append(`
                 <li class='checkOut'>${rooms[i].roomNumber}</li>
             `)
         }
         //展示待清洁房间
         if (rooms[i].RoomSize == '小' && rooms[i].roomState == '待清洁') {
             $('#allRooms .littleRooms').append(`
                 <li class='awaitSweep'>${rooms[i].roomNumber}</li>
             `)
         }

     }
     if ($('#allRooms .littleRooms').html() == '') {
         $('#allRooms .littleRooms').append(`
                 <p>暂无小房间</p>
             `)
     }
 }

 //权限不足提示
 function insufficientPrivileges() {
     //展示权限不足框
     $('#insufficientPrivileges').show().siblings().hide()
     //清除原来的显示数据
     $('#insufficientPrivileges').html('')
     //展示权限不足
     $('#insufficientPrivileges').eq(0).append(`
                 <p>权限不足请联系管理员</p>
             `)
 }

 //编辑房间数据加载
 function editRooms() {
     //显示分页按钮
     $('#editRoomsbutts').addClass('editRoomsbutts')
     //显示编辑房间功能页
     $('main>.optionBody').eq(4).show().siblings().hide()
     anniu()
     go(1)
 }
 // //按钮渲染
 let present = 1 //记录当前页
 //加载选页按钮
 function anniu() {
     //清除原有按钮
     $('.opbtu').remove()
     $('.opbtu2').remove()
     for (let i = 0; i < Math.ceil(rooms.length / 10); i++) {
         $('#next').before(`<li class='opbtu'><span>${i + 1}</span></li>`)
     }
 }
 anniu()
 //点击页数更新数据
 $('#editRoomsbutts').on('click', '.opbtu', function () {
     //获取最新数据库数据
     rooms = getData('room')
     go($(this).text())
 })

 //控制到第几页
 function go(i) {
     //清空原来的 表格
     $('tbody').html('')
     //更改当前页
     present = i * 1
     //更改当前页按钮样式
     $('.opbtu').removeClass('active')
     $('.opbtu').eq(i - 1).addClass('active')
     //添加表格
     let star = (i - 1) * 10
     let end = star + 10
     if (i == Math.ceil(rooms.length / 10)) {
         end = rooms.length
     }
     let j = 0
     for (let i = star; i < end; i++) {
         //房间号(roomNumber)	房间规格(RoomSize)	价格(price)	预览图片(preview)	房间状态(roomState) 备注(remarks)
         //添加一个tr
         $('tbody').append('<tr></tr>')
         //添加td
         $('tbody tr').eq(j).append(`<td>${rooms[i].roomNumber}</td>`)
         $('tbody tr').eq(j).append(`<td>${rooms[i].RoomSize}</td>`)
         $('tbody tr').eq(j).append(`<td>${rooms[i].price}</td>`)
         $('tbody tr').eq(j).append(`<td class='imgPreview'>预览</td>`)
         $('tbody tr').eq(j).append(`<td>${rooms[i].roomState}</td>`)
         $('tbody tr').eq(j).append(`<td>${rooms[i].remarks}</td>`)
         $('tbody tr').eq(j).append(`
         <td>
             <button class="update" title="修改"><span class="iconfont icon-xiugai"></span></button>
             <button class="del" title="删除"><span class="iconfont icon-ziyuanxhdpi "></span></button>
         </td>`)
         j++
     }
     if (present == Math.ceil(rooms.length / 10)) {
         $('#next').addClass('disabled')
     } else {
         $('#next').removeClass('disabled')
     }
     if (present == 1) {
         $('#up').addClass('disabled')
     } else {
         $('#up').removeClass('disabled')
     }
 }
 //默认加载第一页
 go(1)
 //上一页
 $('#up').on('click', function () {
     if (present > 1) {
         go(--present)
     }
 })

 //下一下
 $('#next').on('click', function () {
     if (present < Math.ceil(rooms.length / 10)) {
         go(++present)
     }
 })
 //点击修改图标 弹出修改框
 let newRoomId = null
 $('#editRooms tbody').on('click', '.update', function () {
     $('#alterRoom').modal('show')
     //取点击房间的信息
     let nowroomNun = $(this).parents('tr').find('td').eq(0).text()  //取点击修改的房间号
     let nowRoomSize = $(this).parents('tr').find('td').eq(1).text()  //取点击修改的房间规格
     let nowPrice = $(this).parents('tr').find('td').eq(2).text() //价格
     let nowRoomState = $(this).parents('tr').find('td').eq(4).text()  //房间状态
     let nowRemarkse = $(this).parents('tr').find('td').eq(5).text()   //备注

     //查找当前房间ID
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].roomNumber == nowroomNun) {
             newRoomId = rooms[i].id
             break;
         }

     }

     //设置输入框初始值
     $('#alterRoom #roomNum').val(nowroomNun)
     if (nowRoomSize == '大') {
         $('#alterRoom #RoomSize').children('option').prop('selected', false)
         $('#alterRoom #RoomSize').children('option').eq(0).prop('selected', true)
     } else if (nowRoomSize == '中') {
         $('#alterRoom #RoomSize').children('option').prop('selected', false)
         $('#alterRoom #RoomSize').children('option').eq(1).prop('selected', true)
     } else {
         $('#alterRoom #RoomSize').children('option').prop('selected', false)
         $('#alterRoom #RoomSize').children('option').eq(2).prop('selected', true)
     }
     $('#alterRoom #price').val(nowPrice)
     if (nowRoomState == '已入住') {
         $('#alterRoom #roomState').children('option').prop('selected', false)
         $('#alterRoom #roomState').children('option').eq(0).prop('selected', true)
     } else if (nowRoomState == '待入住') {
         $('#alterRoom #roomState').children('option').prop('selected', false)
         $('#alterRoom #roomState').children('option').eq(1).prop('selected', true)
     } else {
         $('#alterRoom #roomState').children('option').prop('selected', false)
         $('#alterRoom #roomState').children('option').eq(2).prop('selected', true)
     }
     $('#alterRoom #alterRoomRemarks').val(nowRemarkse)
 })
 //点击保存信息
 $('#alterRoomConfirm').on('click', function () {
     //取输入框值
     let nowroomNun = $('#alterRoom #roomNum').val()  //取修改后的房间号
     let nowRoomSize = $('#alterRoom #RoomSize').val() //取修改后的房间规格
     if (nowRoomSize == 0) {
         nowRoomSize = '大'
     } else if (nowRoomSize == 1) {
         nowRoomSize = '中'
     } else {
         nowRoomSize = '小'
     }
     let nowPrice = $('#alterRoom #price').val() //价格
     let nowRoomState = $('#alterRoom #roomState').val() //房间状态
     if (nowRoomState == 0) {
         nowRoomState = '已入住'
     } else if (nowRoomState == 1) {
         nowRoomState = '待入住'
     } else {
         nowRoomState = '待清洁'
     }
     let nowRemarkse = $('#alterRoom #alterRoomRemarks').val()  //备注

     let uproomNun = null //存修改前房间号
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].id == newRoomId) {
             uproomNun = rooms[i].roomNumber
             break;
         }
     }

     //判断输入的房间号是否已存在
     let exist = true //房间号是否存在的状态
     for (let i = 0; i < rooms.length; i++) {
         if (nowroomNun == rooms[i].roomNumber && nowroomNun != uproomNun) {
             //该房间号重复了在不能修改
             exist = false
         }
     }
     if (exist) {
         alterRoom()
     } else {
         console.log('房间号重复不能修改')
         $('#Repetition').modal('show')
         $('#Repetition .modal-body').text(`修改失败(${nowroomNun}房间号已存在)`)

     }
     // 房间号(roomNumber)	房间规格(RoomSize)	价格(price)	预览图片(preview)	房间状态（roomState) 备注(remarks)
     //更改对应房间对象
     function alterRoom() {
         //找到改房间对象
         for (let i = 0; i < rooms.length; i++) {
             if (rooms[i].id == newRoomId) {
                 rooms[i].roomNumber = nowroomNun
                 rooms[i].RoomSize = nowRoomSize
                 rooms[i].price = nowPrice
                 rooms[i].roomState = nowRoomState
                 rooms[i].remarks = nowRemarkse
                 //修改结果存到数据库
                 saveData('room', rooms)
                 break;
             }
         }
         //刷新当前页面数据
         go(present)
     }

 })

 //点击删除图标
 let nowDelroomNun  //存点击删除图标对应的房间号
 $('#editRooms tbody').on('click', '.del', function () {
     //显示确认删除提示框
     $('#affirmDelOperation').modal('show')
     nowDelroomNun = $(this).parents('tr').find('td').eq(0).text()  //取点击修改的房间号
     $('#affirmDelOperation .modal-body').text(`确认删除${nowDelroomNun}号房间吗`)
 })
 //点击删除图标后确认
 $('#affirmDel').on('click', function () {
     //删除对应房间
     for (let i = 0; i < rooms.length; i++) {
         if (rooms[i].roomNumber == nowDelroomNun) {
             console.log('删除成功');
             rooms.splice(i, 1)
             //修改结果存到数据库
             saveData('room', rooms)
             break;
         }
     }
     //更新分页按钮
     anniu()
     //刷新当前页面数据
     if (($('tbody').children('tr').length) - 1) {
         go(present)
     } else {
         go(present - 1)
     }

 })

 //点击添加房间按钮
 $('#addRoomBut').on('click', function () {
     //添加房间的模态框显示
     $('#addRoom').modal('show')
 })

 //点击添加房间的确当
 $('#addRoomRoomConfirm').on('click', function () {
     //读取输入框内容
     let nowroomNun = $('#addroomNum').val()  //取添加的房间号
     let nowRoomSize = $('#roomSizePosition').val() //取添加的房间规格
     if (nowRoomSize == 0) {
         nowRoomSize = '大'
     } else if (nowRoomSize == 1) {
         nowRoomSize = '中'
     } else {
         nowRoomSize = '小'
     }

     let nowPrice = $('#addPrice').val() //价格
     let nowRoomState = '待入住' //房间状态
     let nowRemarkse = $('#addalterRoomRemarks').val()  //备注
     let nowId = 'f' + (Number((rooms[rooms.length - 1].id).slice(1)) + 1)
     let newroom = {
         id: nowId, roomNumber: nowroomNun, RoomSize: nowRoomSize, price: nowPrice,
         preview: ['../images/房间1.webp', '../images/房间2.webp', '../images/房间3.webp'], roomState: nowRoomState, remarks: nowRemarkse

     }
     //房间号或价格不能为空
     if (nowroomNun != '' && nowPrice != '') {
         //判断输入的房间号是否已存在
         let exist = true //房间号是否存在的状态
         for (let i = 0; i < rooms.length; i++) {
             if (nowroomNun == rooms[i].roomNumber) {
                 //该房间号重复了在不能添加
                 exist = false
             }
         }
         if (exist) {
             console.log('房间号不重复可以添加');
             rooms.push(newroom)
             saveData('room', rooms)
             //更新分页按钮
             anniu()
             //刷新当前页面数据
             if (($('tbody').children('tr').length) - 1) {
                 go(present)
             } else {
                 go(present - 1)
             }
         } else {
             console.log('房间号重复不能添加')
             $('#Repetition').modal('show')
             $('#Repetition .modal-body').text(`添加失败(${nowroomNun}房间号已存在)`)
         }
     } else {
         console.log('房间号或价格不能为空')
         $('#Repetition').modal('show')
         $('#Repetition .modal-body').text(`添加失败(房间号或价格不能为空)`)
     }

 })

 //点击查询
 $('#inquire').on('click', function () {
     let nowOption = $('.searchBox select').val()  //取当前选项
     let inquireText = $('.searchBox input').val()  //当前输入值
     let nowData = [] //存符合条件的数组
     //输入值不为空时执行
     if (inquireText) {

         //选项时房间号时
         if (nowOption == 0) {
             //结果
             for (let i = 0; i < rooms.length; i++) {
                 if (rooms[i].roomNumber == inquireText) {
                     nowData.push(rooms[i])
                 }
             }
             if (nowData.length) {
                 //按钮渲染
                 let present2 = 1 //记录当前页
                 //加载选页按钮
                 function anniu2() {
                     //清除原有按钮
                     $('.opbtu').remove()
                     $('.opbtu2').remove()
                     for (let i = 0; i < Math.ceil(nowData.length / 10); i++) {
                         $('#next').before(`<li class='opbtu2'><span>${i + 1}</span></li>`)
                     }
                 }
                 anniu2()
                 //点击页数更新数据
                 $('#editRoomsbutts').on('click', '.opbtu2', function () {
                     //获取最新数据库数据
                     go2($(this).text())
                 })
                 //上一页
                 $('#up').on('click', function () {
                     if (present2 > 1) {
                         go2(--present2)
                     }
                 })

                 //下一下
                 $('#next').on('click', function () {
                     if (present2 < Math.ceil(nowData.length / 10)) {
                         go2(++present2)
                     }
                 })
                 //控制到第几页
                 function go2(i) {
                     //清空原来的 表格
                     $('tbody').html('')
                     //更改当前页
                     present2 = i * 1
                     //更改当前页按钮样式
                     $('.opbtu2').removeClass('active')
                     $('.opbtu2').eq(i - 1).addClass('active')
                     //添加表格
                     let star = (i - 1) * 10
                     let end = star + 10
                     if (i == Math.ceil(nowData.length / 10)) {
                         end = nowData.length
                     }
                     let j = 0
                     for (let i = star; i < end; i++) {
                         //房间号(roomNumber)	房间规格(RoomSize)	价格(price)	预览图片(preview)	房间状态(roomState) 备注(remarks)
                         //添加一个tr
                         $('tbody').append('<tr></tr>')
                         //添加td
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomNumber}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].RoomSize}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].price}</td>`)
                         $('tbody tr').eq(j).append(`<td>预览</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomState}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].remarks}</td>`)
                         $('tbody tr').eq(j).append(`
                         <td>
                             <button class="update" title="修改"><span class="iconfont icon-xiugai"></span></button>
                             <button class="del" title="删除"><span class="iconfont icon-ziyuanxhdpi "></span></button>
                         </td>`)
                         j++
                     }
                     if (present2 == Math.ceil(nowData.length / 10)) {
                         $('#next').addClass('disabled')
                     } else {
                         $('#next').removeClass('disabled')
                     }
                     if (present2 == 1) {
                         $('#up').addClass('disabled')
                     } else {
                         $('#up').removeClass('disabled')
                     }
                 }
                 //默认加载第一页
                 go2(1)
             } else {
                 $('#Repetition').modal('show')
                 $('#Repetition .modal-body').text(`没有此房间号`)
             }
         } else if (nowOption == 1) {
             //结果
             for (let i = 0; i < rooms.length; i++) {
                 if (rooms[i].RoomSize == inquireText) {
                     nowData.push(rooms[i])
                 }
             }
             if (nowData.length) {
                 //按钮渲染
                 let present2 = 1 //记录当前页
                 //加载选页按钮
                 function anniu2() {
                     //清除原有按钮
                     $('.opbtu').remove()
                     $('.opbtu2').remove()
                     for (let i = 0; i < Math.ceil(nowData.length / 10); i++) {
                         $('#next').before(`<li class='opbtu2'><span>${i + 1}</span></li>`)
                     }
                 }
                 anniu2()
                 //点击页数更新数据
                 $('#editRoomsbutts').on('click', '.opbtu2', function () {
                     //获取最新数据库数据
                     go2($(this).text())
                 })

                 //控制到第几页
                 function go2(i) {
                     //清空原来的 表格
                     $('tbody').html('')
                     //更改当前页
                     present2 = i * 1
                     //更改当前页按钮样式
                     $('.opbtu2').removeClass('active')
                     $('.opbtu2').eq(i - 1).addClass('active')
                     //添加表格
                     let star = (i - 1) * 10
                     let end = star + 10
                     if (i == Math.ceil(nowData.length / 10)) {
                         end = nowData.length
                     }
                     let j = 0
                     for (let i = star; i < end; i++) {
                         //房间号(roomNumber)	房间规格(RoomSize)	价格(price)	预览图片(preview)	房间状态(roomState) 备注(remarks)
                         //添加一个tr
                         $('tbody').append('<tr></tr>')
                         //添加td
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomNumber}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].RoomSize}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].price}</td>`)
                         $('tbody tr').eq(j).append(`<td>预览</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomState}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].remarks}</td>`)
                         $('tbody tr').eq(j).append(`
                         <td>
                             <button class="update" title="修改"><span class="iconfont icon-xiugai"></span></button>
                             <button class="del" title="删除"><span class="iconfont icon-ziyuanxhdpi "></span></button>
                         </td>`)
                         j++
                     }
                     if (present2 == Math.ceil(nowData.length / 10)) {
                         $('#next').addClass('disabled')
                     } else {
                         $('#next').removeClass('disabled')
                     }
                     if (present2 == 1) {
                         $('#up').addClass('disabled')
                     } else {
                         $('#up').removeClass('disabled')
                     }
                 }
                 //默认加载第一页
                 go2(1)
                 //上一页
                 $('#up').on('click', function () {
                     if (present2 > 1) {
                         go2(--present2)
                     }
                 })

                 //下一下
                 $('#next').on('click', function () {
                     if (present2 < Math.ceil(nowData.length / 10)) {
                         go2(++present2)
                     }
                 })
             } else {
                 $('#Repetition').modal('show')
                 $('#Repetition .modal-body').text(`没有此规格的房间`)
             }
         } else if (nowOption == 2) {
             //结果
             for (let i = 0; i < rooms.length; i++) {
                 if (rooms[i].roomState == inquireText) {
                     nowData.push(rooms[i])
                 }
             }
             if (nowData.length) {
                 //按钮渲染
                 let present2 = 1 //记录当前页
                 //加载选页按钮
                 function anniu2() {
                     //清除原有按钮
                     $('.opbtu').remove()
                     $('.opbtu2').remove()
                     for (let i = 0; i < Math.ceil(nowData.length / 10); i++) {
                         $('#next').before(`<li class='opbtu2'><span>${i + 1}</span></li>`)
                     }
                 }
                 anniu2()
                 //点击页数更新数据
                 $('#editRoomsbutts').on('click', '.opbtu2', function () {
                     //获取最新数据库数据
                     go2($(this).text())
                 })

                 //控制到第几页
                 function go2(i) {
                     //清空原来的 表格
                     $('tbody').html('')
                     //更改当前页
                     present2 = i * 1
                     //更改当前页按钮样式
                     $('.opbtu2').removeClass('active')
                     $('.opbtu2').eq(i - 1).addClass('active')
                     //添加表格
                     let star = (i - 1) * 10
                     let end = star + 10
                     if (i == Math.ceil(nowData.length / 10)) {
                         end = nowData.length
                     }
                     let j = 0
                     for (let i = star; i < end; i++) {
                         //房间号(roomNumber)	房间规格(RoomSize)	价格(price)	预览图片(preview)	房间状态(roomState) 备注(remarks)
                         //添加一个tr
                         $('tbody').append('<tr></tr>')
                         //添加td
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomNumber}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].RoomSize}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].price}</td>`)
                         $('tbody tr').eq(j).append(`<td>预览</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].roomState}</td>`)
                         $('tbody tr').eq(j).append(`<td>${nowData[i].remarks}</td>`)
                         $('tbody tr').eq(j).append(`
                         <td>
                             <button class="update" title="修改"><span class="iconfont icon-xiugai"></span></button>
                             <button class="del" title="删除"><span class="iconfont icon-ziyuanxhdpi "></span></button>
                         </td>`)
                         j++
                     }
                     if (present2 == Math.ceil(nowData.length / 10)) {
                         $('#next').addClass('disabled')
                     } else {
                         $('#next').removeClass('disabled')
                     }
                     if (present2 == 1) {
                         $('#up').addClass('disabled')
                     } else {
                         $('#up').removeClass('disabled')
                     }
                 }
                 //默认加载第一页
                 go2(1)
                 //上一页
                 $('#up').on('click', function () {
                     if (present2 > 1) {
                         go2(--present2)
                     }
                 })

                 //下一下
                 $('#next').on('click', function () {
                     if (present2 < Math.ceil(nowData.length / 10)) {
                         go2(++present2)
                     }
                 })
             } else {
                 $('#Repetition').modal('show')
                 $('#Repetition .modal-body').text(`没有此状态的房间`)
             }
         }

     } else {
         console.log('啥也没有');
         $('#Repetition').modal('show')
         $('#Repetition .modal-body').text(`输入不能为空`)
         anniu()
         go(1)
     }

 })
 // 显示当前登录者头像及工号
showHeadImgId()

// 头部退出按钮
$('#quit').find('button').click(function(){
    open('./login.html','_self')
}) 

//显示当前登录者头像及工号
function showHeadImgId(){
let useData = getData('staff')
let loginUser = getData('loginUser').jobNumber
for(let i=0;i<useData.length;i++){
   if(useData[i].jobNumber == loginUser){
        $('.portrait').find('img').attr('src',useData[i].headPortrait)
        $('#quit').find('.jobId').html(useData[i].jobNumber)
        }

   }
}

//显示预览图
$('tbody').on('click', '.imgPreview', function () {
    $("#roomPreview").show()
    //获取房间号
    let nowRoomNum = $(this).siblings().eq(0).text()
    let roomImgs = []
    for (let i = 0; i < rooms.length; i++) {
        if (rooms[i].roomNumber == nowRoomNum) {
            roomImgs = rooms[i].preview;
            break;
        }
    }
    $('#roomPreview img').eq(0).attr('src', roomImgs[0])
    $('#roomPreview img').eq(1).attr('src', roomImgs[1])
    $('#roomPreview img').eq(2).attr('src', roomImgs[2])
})
//关闭预览图
$('.off').on('click',function(){
    $("#roomPreview").hide()
})